package MR;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class Driver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        args = new String[]{"F:/Lagou/one/input", "F:/Lagou/one/output"};
        //1.获取配置信息以及封装任务
        Job job = Job.getInstance(new Configuration());

        //2.设置jar加载路径
        job.setJarByClass(Driver.class);

        //3. 设置Mapper和Reducer
        job.setMapperClass(Map.class);
        job.setReducerClass(Red.class);

        //4. 指定Map输出kv数据类型
        job.setMapOutputKeyClass(LongWritable.class);
        job.setMapOutputValueClass(IntWritable.class);

        //5. 指定job处理的原始数据路径
        FileInputFormat.setInputPaths(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        //6.提交任务
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }
}
